<?php

namespace app\admin\controller\column;

use app\admin\model\SchemeShow;
use app\common\controller\AdminController;
use app\common\controller\Adminds;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;
use think\App;

/**
 * @ControllerAnnotation(title="column_clist")
 */
class Clist extends Adminds
{

    use \app\admin\traits\Curd;

    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->model = new \app\admin\model\ColumnClist();
        
    }
    //添加
    public function addAllColumn(){

        $list = $this->model->field('id,name,column,type')->select();
        $this->result($list, 0,'操作成功');
    }
    //编辑
    public function editAllColumn($id){
        $fields = SchemeShow::where('id',$id)->value('fields');


        $list = $this->model->field('id,name,column,type')->select();

        foreach($list as $v){
            $v['is_check'] = 0;
            if(in_array($v['id'],$fields)){
                $v['is_check'] = 1;
            }
        }
        $this->result($list, 0,'操作成功');
    }
    //根据类型返回所有字段
    public function showColumnByType($type){
        $fields = SchemeShow::where('type',$type)->value('fields');
        $list = $this->model->where('type',$type)->whereIn('id',$fields)->field('id,name,column,type')->select();
        $this->result($list, 0,'操作成功');
    }

    
}